//
//  WKMineListVC.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/4.
//  Copyright © 2018年 何文虎. All rights reserved.
//

#import "WKMineListVC.h"
#import "WKMineHeaderView.h"
#import "WKMineListCell.h"
#import "WKDoubiListViewController.h"
#import "WKMessgeViewController.h"

@interface WKMineListVC ()<UITableViewDelegate,UITableViewDataSource>
{
    WKMineHeaderView *_headerView;
}
@property(nonatomic,strong)UITableView *tableView;
@end

@implementation WKMineListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViews];
}

- (void)initViews{

    self.view.backgroundColor = [UIColor whiteColor];
    self.naviBar.title = @"我的";
    self.naviBar.leftBtn.hidden = YES;
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenHeight, ScreenHeight) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [_tableView registerClass:[WKMineListCell class] forCellReuseIdentifier:NSStringFromClass([WKMineListCell class])];
    
    _headerView = [[WKMineHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, NavBarHeight+300)];
    _tableView.tableHeaderView = _headerView;
    _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, TabBarHeight)];
    
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    @weakify(self);
    _headerView.navBlock = ^(NSInteger index) {
        @strongify(self);
        if (index==0) {
            WKMessgeViewController *messgeVC = [[WKMessgeViewController alloc]init];
            [self.navigationController pushViewController:messgeVC animated:NO];
        }
    };
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *titleArr = @[@"预约",@"浏览记录",@"任务中心",@"兑换商城",@"分享有礼",@"用户反馈"];
    WKMineListCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([WKMineListCell class]) forIndexPath:indexPath];
    cell.titleLb.text = titleArr[indexPath.row];
    if (indexPath.row<=1) {
        NSArray *detailArr = @[@"立省200元",@"看看你省了多少钱"];
        cell.detailLb.text = detailArr[indexPath.row];
    }
    
    if (indexPath.row==5) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }else{
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WKDoubiListViewController *doubiListVC = [[WKDoubiListViewController alloc]init];
    doubiListVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:doubiListVC animated:NO];
}


@end
